﻿<include file="Common/header" /> 
<title>添加角色</title>
<style>
.norag { border: none !important; font-weight: normal !important }
.input-text, .select-box { width: 300px; border-radius: 3px; }
.formControls { float: left; margin-right: 20px; }
</style>
</head>
<body>
<nav class="breadcrumb"> <i class="Hui-iconfont"></i> {:location();} <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont"></i></a> </nav>
<div class="pd-20">
  <form class="sites_add" action="" method="post">
    <table class="table table-bg " style="border-top:none">
      <tbody>
        <tr>
          <td width="80">角色名称:</td>
          <td><div class="formControls">
              <input type="text" class="input-text radius" value="{$role_name}"  placeholder="" name="role_name" datatype="*2-16" nullmsg="角色名称不能为空">
            </div>
            <div> </div></td>
        </tr>
        <tr>
          <td>权限控制:</td>
          <td><div class="row cl">
              <div class="formControls col-xs-8 col-sm-9">
              <volist name="menu" id="vo">
                <dl class="permission-list">
                  <dt>
                    <label>
                      <input type="checkbox"  value="{$vo.id}" name="menu_ids[]" id="user-Character-0">
                      {$vo.name}</label>
                  </dt>
                  <dd>
                  <volist name="vo['child']" id="v">
                    <dl class="cl permission-list2">
                      <dt>
                        <label class="">
                          <input type="checkbox" value="{$v.id}" name="menu_ids[]" id="user-Character-0-0">
                           {$v.name}</label>
                      </dt>
                      
                      <volist name="v['child']" id='vv'>
                      <dd>
                        <label class="">
                          <input type="checkbox" value="{$vv.id}" name="menu_ids[]" id="user-Character-0-0-0">
                          {$vv.name}</label>
                          
                        <foreach  name="vv['child']" item='vvv'>
                            <label class="">
                          <input type="checkbox" value="{$vvv.id}" name="menu_ids[]" id="user-Character-0-0-0-0">
                          {$vvv.name}</label> 
                        </foreach >
              
                      </dd>
                      
                      </volist>
                      
                    </dl>
                     
                     </volist>
                     
                  </dd>
                </dl>
                 
                 </volist>
              </div>
            </div></td>
        </tr>
        <tr>
          <td>备注:</td>
          <td><div class="formControls col-xs-8 col-sm-9" >
              <textarea class="textarea radius"  style="width:300px;" placeholder="说点什么..." rows="" cols="" name="remark">{$remark}</textarea>
            </div></td>
        </tr>
        <tr>
          <td>状态:</td>
          <td><span class="select-box radius">
            <select class="select" size="1" name="status">
              <option value="1" <if condition="$status eq 1"> selected</if> >启用</option>
              <option value="0" <if condition="$status eq '0'">selected </if> >关闭</option>
            </select>
            </span></td>
        </tr>
      </tbody>
    </table>
    <div class="btn_wrap" style="margin-top:15px">
      <div class="btn_wrap_pd">
        <button class="btn btn-primary radius " type="submit" style="padding:0 22px">添加</button>
      </div>
    </div>
  </form>
</div>
<script type="text/javascript">
$(function(){
 	$(".sites_add").Validform({tiptype:2,ajaxurl:{} });
	
	$(".permission-list dt input:checkbox").click(function(){
		$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
	});
	$(".permission-list2 dd input:checkbox").click(function(){
		var l =$(this).parent().parent().find("input:checked").length;
		var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
		if($(this).prop("checked")){
			$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
			$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
		}
		else{
			if(l==0){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
			}
			if(l2==0){
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
			}
		}
	});
	
 
	//东哥遍历选择
	var str="{$menu_ids}";
	var strs= new Array(); 
	strs=str.split(',');
	$("input[name='menu_ids[]']").each(function(){
		if(in_array($(this).val(),strs)){ 
			$(this).attr('checked','checked');
			}
		});
	
});

function in_array(search,array){
    for(var i in array){
        if(array[i]==search){ 
            return true;
        }
    }
    return false;
}
</script>
</body>
</html>